class_name InputManager
extends RefCounted


enum InputSchema {
	P1, P2
}

enum InputAction {
	LEFT, RIGHT, UP, DOWN, PASS, SHOOT
}

const ACTION_MAP: Dictionary[InputSchema,Dictionary] = {
	InputSchema.P1: {
		InputAction.LEFT: "p1_left",
		InputAction.RIGHT: "p1_right",
		InputAction.UP: "p1_up",
		InputAction.DOWN: "p1_down",
		InputAction.PASS: "p1_pass",
		InputAction.SHOOT: "p1_shoot"
	},
	InputSchema.P2: {
		InputAction.LEFT: "p2_left",
		InputAction.RIGHT: "p2_right",
		InputAction.UP: "p2_up",
		InputAction.DOWN: "p2_down",
		InputAction.PASS: "p2_pass",
		InputAction.SHOOT: "p2_shoot"
	}
}



var enabled: bool :
	get:
		return _enabled
	set(value):
		_enabled = value

var movement_direction: Vector2:
	get:
		return _direction



var _enabled: bool = true
var _schema: InputSchema
var _direction: Vector2 = Vector2.ZERO


func _init(schema: InputSchema):
	_schema = schema


func process_input():
	if not _enabled:
		return
	movement()




func is_movement() -> bool:
	return _direction != Vector2.ZERO


func is_tackling() -> bool:
	return is_action_just_pressed(_schema, InputAction.SHOOT)


func is_shooting() -> bool:
	return is_action_pressed(_schema, InputAction.SHOOT)


func is_shoot_pressed() -> bool:
	return is_action_just_pressed(_schema, InputAction.SHOOT)


func is_shoot_released() -> bool:
	return is_action_just_released(_schema, InputAction.SHOOT)


func is_pass_pressed() -> bool:
	return is_action_just_pressed(_schema, InputAction.PASS)


func is_pass_released() -> bool:
	return is_action_just_released(_schema, InputAction.PASS)



func movement() -> Vector2:
	if not _enabled:
		_direction = Vector2.ZERO
		return _direction

	_direction = get_vector(_schema)
	return _direction





func get_vector(schema: InputSchema) -> Vector2:
	var act := ACTION_MAP[schema]
	return Input.get_vector(act[InputAction.LEFT], act[InputAction.RIGHT], act[InputAction.UP], act[InputAction.DOWN])

func is_action_pressed(schema: InputSchema, action: InputAction) -> bool:
	return Input.is_action_pressed(ACTION_MAP[schema][action])

func is_action_just_pressed(schema: InputSchema, action: InputAction) -> bool:
	return Input.is_action_just_pressed(ACTION_MAP[schema][action])


func is_action_just_released(schema: InputSchema, action: InputAction) -> bool:
	return Input.is_action_just_released(ACTION_MAP[schema][action])
